﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.IO;
using System.Collections.ObjectModel;

namespace BDSim
{
    public class NavMsgFit
    {
        #region 字段

        private MasterStation _Parent;

        public List<OrbitSimData> OrbitPVList = new List<OrbitSimData>(); //轨道数据(用于拟合星历参数)
        public List<ClkSimData> ClockList     = new List<ClkSimData>();   //钟差数据(用于拟合钟差参数)       
        //public Dictionary<string, List<Ephemeris_16>> SatEph16Dic = new Dictionary<string, List<Ephemeris_16>>(); /// key（string）代表卫星名称，value代表当前卫星所有星历     
        //public Dictionary<string, List<ClkErrFitMsg>> ClockErrDic = new Dictionary<string, List<ClkErrFitMsg>>();  /// key（string）代表卫星名称，value代表当前卫星所有钟差值
        //public List<IonoFit_OutputMsg> IonoFitOutputMsgList = new List<IonoFit_OutputMsg>();

        /// <summary>
        /// 待计算的卫星所属星座类型(用于RINEX格式输出)
        /// </summary>
        private EConstellationType _EConstellation_type;               

        #region 添加星历误差控制参数

        /// <summary>
        /// 星历拟合是否添加轨道误差
        /// </summary>
        private bool _IsAddOrbitErr_Navfit;

        /// <summary>
        /// 系统仿真起始时间
        /// </summary>
        private UTCTime _SysStartTime;

        /// <summary>
        /// 仿真步长
        /// </summary>
        private double _SimStep;


        #region MEO卫星轨道误差配置（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        private double _MEO_H_leve;

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        private double _AddOrbitErr_MEO_T;

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        private double _MEO_AmpR;

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        private double _MEO_AmpT;
     
        /// <summary>
        /// N方向添加误差值
        /// </summary>
        private double _MEO_AmpN;

        #endregion

        #region IGSO卫星轨道误差配置（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        private double _IGSO_H_leve;

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        private double _AddOrbitErr_IGSO_T;

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        private double _IGSO_AmpR;

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        private double _IGSO_AmpT;

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        private double _IGSO_AmpN;

        #endregion

        #region GEO卫星轨道误差配置（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        private double _GEO_H_leve;

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        private double _AddOrbitErr_GEO_T;

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        private double _GEO_AmpR;

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        private double _GEO_AmpT;

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        private double _GEO_AmpN;

        #endregion

        #region LEO卫星轨道误差配置（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        private double _LEO_H_leve;

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        private double _AddOrbitErr_LEO_T;

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        private double _LEO_AmpR;

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        private double _LEO_AmpT;

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        private double _LEO_AmpN;

        #endregion

        #region HEO卫星轨道误差配置（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        private double _HEO_H_leve;

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        private double _AddOrbitErr_HEO_T;

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        private double _HEO_AmpR;

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        private double _HEO_AmpT;

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        private double _HEO_AmpN;

        #endregion

        #endregion

        #endregion

        #region 属性

        public MasterStation Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        /// <summary>
        /// 待计算的卫星所属星座类型(用于RINEX格式输出)
        /// </summary>
        [Browsable(false)]
        public EConstellationType EConstellation_type
        {
            get { return _EConstellation_type; }
            set { _EConstellation_type = value; }
        }

        /// <summary>
        /// 星历拟合是否添加轨道误差
        /// </summary>
        public bool IsAddOrbitErr_Navfit
        {
            get { return _IsAddOrbitErr_Navfit; }
            set { _IsAddOrbitErr_Navfit = value; }
        }
        
        /// <summary>
        /// 系统仿真起始时间
        /// </summary>
        public UTCTime SysStartTime
        {
            get { return _SysStartTime; }
            set { _SysStartTime = value; }
        }

        /// <summary>
        /// 仿真步长
        /// </summary>
        public double SimStep
        {
            get { return _SimStep; }
            set { _SimStep = value; }
        }

        #region MEO添加轨道误差（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        public double MEO_H_leve
        {
            get { return _MEO_H_leve; }
            set { _MEO_H_leve = value; }
        }

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        public double AddOrbitErr_MEO_T
        {
            get { return _AddOrbitErr_MEO_T; }
            set { _AddOrbitErr_MEO_T = value;}
        }

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        public double MEO_AmpR
        {
            get { return _MEO_AmpR; }
            set { _MEO_AmpR = value; }
        }

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        public double MEO_AmpT
        {
            get { return _MEO_AmpT; }
            set { _MEO_AmpT = value; }
        }

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        public double MEO_AmpN
        {
            get { return _MEO_AmpN; }
            set { _MEO_AmpN = value; }
        }
        #endregion

        #region IGSO添加轨道误差（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        public double IGSO_H_leve
        {
            get { return _IGSO_H_leve; }
            set { _IGSO_H_leve = value; }
        }

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        public double AddOrbitErr_IGSO_T
        {
            get { return _AddOrbitErr_IGSO_T; }
            set { _AddOrbitErr_IGSO_T = value; }
        }

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        public double IGSO_AmpR
        {
            get { return _IGSO_AmpR; }
            set { _IGSO_AmpR = value; }
        }

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        public double IGSO_AmpT
        {
            get { return _IGSO_AmpT; }
            set { _IGSO_AmpT = value; }
        }

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        public double IGSO_AmpN
        {
            get { return _IGSO_AmpN; }
            set { _IGSO_AmpN = value; }
        }
        #endregion

        #region GEO添加轨道误差（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        public double GEO_H_leve
        {
            get { return _GEO_H_leve; }
            set { _GEO_H_leve = value; }
        }

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        public double AddOrbitErr_GEO_T
        {
            get { return _AddOrbitErr_GEO_T; }
            set { _AddOrbitErr_GEO_T = value; }
        }

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        public double GEO_AmpR
        {
            get { return _GEO_AmpR; }
            set { _GEO_AmpR = value; }
        }

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        public double GEO_AmpT
        {
            get { return _GEO_AmpT; }
            set { _GEO_AmpT = value; }
        }

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        public double GEO_AmpN
        {
            get { return _GEO_AmpN; }
            set { _GEO_AmpN = value; }
        }
        #endregion

        #region LEO卫星轨道误差配置（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        public double LEO_H_leve
        {
            get { return _LEO_H_leve; }
            set { _LEO_H_leve = value; }
        }

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        public double AddOrbitErr_LEO_T
        {
            get { return _AddOrbitErr_LEO_T; }
            set { _AddOrbitErr_LEO_T = value; }
        }

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        public double LEO_AmpR
        {
            get { return _LEO_AmpR; }
            set { _LEO_AmpR = value; }
        }

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        public double LEO_AmpT
        {
            get { return _LEO_AmpT; }
            set { _LEO_AmpT = value; }
        }

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        public double LEO_AmpN
        {
            get { return _LEO_AmpN; }
            set { _LEO_AmpN = value; }
        }

        #endregion

        #region HEO卫星轨道误差配置（用于星历拟合）
        /// <summary>
        /// 白噪声误差量级,建议加在厘米量级
        /// </summary>
        public double HEO_H_leve
        {
            get { return _HEO_H_leve; }
            set { _HEO_H_leve = value; }
        }

        /// <summary>
        /// 轨道误差周期
        /// </summary>
        public double AddOrbitErr_HEO_T
        {
            get { return _AddOrbitErr_HEO_T; }
            set { _AddOrbitErr_HEO_T = value; }
        }

        /// <summary>
        /// R方向添加误差值
        /// </summary>
        public double HEO_AmpR
        {
            get { return _HEO_AmpR; }
            set { _HEO_AmpR = value; }
        }

        /// <summary>
        /// T方向添加误差值
        /// </summary>      
        public double HEO_AmpT
        {
            get { return _HEO_AmpT; }
            set { _HEO_AmpT = value; }
        }

        /// <summary>
        /// N方向添加误差值
        /// </summary>
        public double HEO_AmpN
        {
            get { return _HEO_AmpN; }
            set { _HEO_AmpN = value; }
        }

        #endregion

        #endregion

        #region 构造函数（包含调用方法）

        #endregion

        #region 实时运行函数

        #endregion

        #region 功能一：星历参数拟合实现

        /// <summary>
        /// 按照仿真总时长，每1个小时拟合一次星历数据，采用2小时数据进行拟合
        /// </summary>
        public void Msg_NavFit(ObservableCollection<Satellite> AllSatelliteMsg, EConstellationType NavSysType)
        {
            /////kj添加
            // string path = Directory.GetCurrentDirectory() + "\\DataRecords\\地面段\\自定义数据_";
            //DateTime NowTime = DateTime.Now;
            //string NowTimeString = NowTime.Year.ToString() + string.Format("{0:D2}", NowTime.Month) + string.Format("{0:D2}", NowTime.Day) +
            //    "_" + string.Format("{0:D2}", NowTime.Hour) + "_" + string.Format("{0:D2}", NowTime.Minute) + "_" + string.Format("{0:D2}", NowTime.Second);
            //path = path + NowTimeString + "\\";   


            //获取仿真时所跨越长的整小时数
            double TempDOuble = (BDSimObject.GlobalEndTime.JD - BDSimObject.GlobalStartTime.JD) / ((double)3600 / 86400);
            int hourNum = (int)Math.Ceiling((Convert.ToDouble(TempDOuble.ToString("0.00000"))));

            //遍历所有卫星       
            foreach (var SatMsg in AllSatelliteMsg)
            {  
               // ///////kj添加
               //string  OrbitECFFileName= path + "\\导航电文轨道数据\\ECF\\";
               //if (!Directory.Exists(OrbitECFFileName))
               //{
               //    Directory.CreateDirectory(OrbitECFFileName);
               //}
               //OrbitECFFileName += "BDSim_" + SatMsg.Name + "_ECF.txt";
               // ////////

                for (int i = 0; i < hourNum; i++)
                {
                    OrbitPVList = SatMsg.OrbitPVList;

                    string satName = SatMsg.Name;   

                    int SimStep = (int)((OrbitPVList[2].SatPV_ECI.epoch.JD - OrbitPVList[1].SatPV_ECI.epoch.JD) * 86400.0+0.0001);  //轨道数据步长  

                    int Num = 0;  //计算只需2个小时轨道数据，Num为计算需要存储的轨道组数        

                    if (SimStep > 0)
                    {
                        Num = 7200 / SimStep;
                    }

                    List<NodePosVel> SatECIList = new List<NodePosVel>();

                    for (int j = 0; j < Num; j++)
                    {
                        SatECIList.Add(OrbitPVList[i *(3600/SimStep) + j].SatPV_ECI);                        
                    }

                    UTCTime FitTime = SatECIList[0].epoch;

                    NodePosVel[] pvArray = new NodePosVel[Num];

                    //将需要的数据从satECIList复制到pvArray中
                    SatECIList.CopyTo(0, pvArray, 0, Num);

                    EphErrParam AddErrParam = new EphErrParam();

                    int SatType = 0;
                    SatOrbit.enumSatType enumtempSatType = SatOrbit.GetSatType(SatECIList[0]);  //静态方法不用实例化一个类
                    switch (enumtempSatType)
                    {
                        case SatOrbit.enumSatType.MEO:
                            SatType = 1;
                            AddErrParam.H_leve = _MEO_H_leve;
                            AddErrParam.T = _AddOrbitErr_MEO_T;
                            AddErrParam.AmpR = _MEO_AmpR;
                            AddErrParam.AmpT = _MEO_AmpT;
                            AddErrParam.AmpN = _MEO_AmpN;
                            break;
                        case SatOrbit.enumSatType.GEO:
                            SatType = 2;
                            AddErrParam.H_leve = _GEO_H_leve;
                            AddErrParam.T = _AddOrbitErr_GEO_T;
                            AddErrParam.AmpR = _GEO_AmpR;
                            AddErrParam.AmpT = _GEO_AmpT;
                            AddErrParam.AmpN = _GEO_AmpN;
                            break;
                        case SatOrbit.enumSatType.IGSO:
                            SatType = 0;
                            AddErrParam.H_leve = _IGSO_H_leve;
                            AddErrParam.T = _AddOrbitErr_IGSO_T;
                            AddErrParam.AmpR = _IGSO_AmpR;
                            AddErrParam.AmpT = _IGSO_AmpT;
                            AddErrParam.AmpN = _IGSO_AmpN;
                            break;
                        case SatOrbit.enumSatType.LEO:
                            SatType = 3;    //------------算法未实现
                            AddErrParam.H_leve = _LEO_H_leve;
                            AddErrParam.T = _AddOrbitErr_LEO_T;
                            AddErrParam.AmpR = _LEO_AmpR;
                            AddErrParam.AmpT = _LEO_AmpT;
                            AddErrParam.AmpN = _LEO_AmpN;
                            break;
                        case SatOrbit.enumSatType.HEO:
                            SatType = 4;    //------------算法未实现
                            AddErrParam.H_leve = _HEO_H_leve;
                            AddErrParam.T = _AddOrbitErr_HEO_T;
                            AddErrParam.AmpR = _HEO_AmpR;
                            AddErrParam.AmpT = _HEO_AmpT;
                            AddErrParam.AmpN = _HEO_AmpN;
                            break;
                        default:
                            break;
                    }

                    /*输入参数 */
                    NavEphFit_Input InputParam=new NavEphFit_Input ();
                    InputParam.FitTime = FitTime;
                    InputParam.NavSysType = NavSysType; 
                    InputParam.SatType = SatType;
                    InputParam.SysStartTime = BDSimObject.GlobalStartTime;
                    InputParam.LeapSec = ReadEOP.EOP_GetLeapSec(FitTime) + 19;
                    
                    /*控制参数 */
                    NavEphFit_ControlParam ControlParam=new NavEphFit_ControlParam ();
                    bool IsAddError = (Parent.Parent.Parent.Parent.Parent as Scenario).EnableFitError;//场景星历拟合误差开关控制  
                    ControlParam.IsAddErr = Convert.ToInt16(IsAddError);
                    ControlParam.SunPert = Convert.ToInt16(SatMsg.Orbit.COrbitPredictParam.SunPert);
                    ControlParam.MoonPert = Convert.ToInt16(SatMsg.Orbit.COrbitPredictParam.MoonPert);
                    ControlParam.ErrParam = AddErrParam;

                    NavEphFit_Output output = new NavEphFit_Output();
                    int flag = EphemerisDLL.NavBGREEph_AddError(InputParam, SimStep, Num, pvArray, ControlParam, out output);

                    //NodePosVel Nav_ECF = new NodePosVel();
                    //double tempt = output.SixEph.toe;
                    //for (int Add_t = 0; Add_t < 3600; Add_t++)
                    //{                        
                    //     EphemerisDLL.CalNav16ToPV(output.SixEph, InputParam.SatType, tempt, out Nav_ECF, 2);

                    //     UTCToStringClass utcstr = new UTCToStringClass();
                    //     string UTCStr = utcstr.NewUTCToString(Nav_ECF.epoch);
                    //     string tempcontent = UTCStr + "    " +
                    //                       Nav_ECF.X.ToString("0.000000").PadLeft(17, ' ') +
                    //              "    " + Nav_ECF.Y.ToString("0.000000").PadLeft(17, ' ') +
                    //              "    " + Nav_ECF.Z.ToString("0.000000").PadLeft(17, ' ') +
                    //              "    " + Nav_ECF.vx.ToString("0.000000").PadLeft(14, ' ') +
                    //              "    " + Nav_ECF.vy.ToString("0.000000").PadLeft(14, ' ') +
                    //              "    " + Nav_ECF.vz.ToString("0.000000").PadLeft(14, ' ') + "\r\n";
                    //     File.AppendAllText(OrbitECFFileName, tempcontent);
                    //     tempt = tempt + 1;
                    //}                  
                    
                    switch (InputParam.NavSysType)
                    {
                        //抽取星历16参
                        case EConstellationType.BD:
                        case EConstellationType.GALILEO:
                        case EConstellationType.GPS:                            
                            if (Parent.SatEph16Dic.ContainsKey(satName))//如果字典有SatName，增加值
                            {
                                Parent.SatEph16Dic[satName].Add(output.SixEph);
                            }
                            else //如果字典里没有SatName,则新增SatName和值
                            {
                                Parent.SatEph16Dic.Add(satName, new List<Ephemeris_16>());
                                Parent.SatEph16Dic[satName].Add(output.SixEph);
                            }
                            break;
                        case EConstellationType.GLONASS:
                            if (Parent.GloSatEphDic.ContainsKey(satName))//如果字典有SatName，增加值
                            {
                                Parent.GloSatEphDic[satName].Add(output.GloEph);
                            }
                            else //如果字典里没有SatName,则新增SatName和值
                            {
                                Parent.GloSatEphDic.Add(satName, new List<GlonassEph>());
                                Parent.GloSatEphDic[satName].Add(output.GloEph);
                            }
                            break;
                    }   
                }

            }        

            
        }

        ///// <summary>
        ///// 识别卫星类型
        ///// </summary>
        ///// <param name="satPV">卫星轨道位置速度</param>
        ///// <returns>卫星类型（0:IGSO,1:MEO,2:GEO）</returns>
        //public int IdentifySatType(NodePosVel satPV)
        //{
        //    int satType = 1;
        //    double orbitAltitude = CalculateOrbitAltitude(satPV);
        //    if (orbitAltitude < 30000000 && orbitAltitude > 20000000)
        //    {
        //        satType = 1;//MEO卫星
        //    }
        //    else if (Math.Abs(satPV.VZ) < 100 && orbitAltitude > 33000000)
        //    {
        //        satType = 2;//GEO卫星
        //    }
        //    else if (Math.Abs(satPV.VZ) > 100 && orbitAltitude > 33000000)
        //    {
        //        satType = 0;//IGSO卫星
        //    }
        //    return satType;
        //}

        ///// <summary>
        ///// 计算卫星的轨道半径
        ///// </summary>
        ///// <param name="satECF"></param>
        ///// <returns></returns>
        //double CalculateOrbitAltitude(NodePosVel satECF)
        //{
        //    double orbitAltitude = 0;
        //    double temp = 0;
        //    temp += satECF.x * satECF.x;
        //    temp += satECF.y * satECF.y;
        //    temp += satECF.z * satECF.z;
        //    orbitAltitude = Math.Sqrt(temp);
        //    return orbitAltitude;
        //}

        #endregion

        #region 功能二：钟差参数拟合实现
      
        /// <summary>
        /// 按照仿真总时长，每1个小时拟合一次钟差数据，采用2小时数据进行拟合
        /// </summary>
        public void Msg_ClkFit(ObservableCollection<Satellite> AllSatelliteMsg)
        {
            //获取仿真时所跨越长的整小时数
            double TempDOuble = (BDSimObject.GlobalEndTime.JD - BDSimObject.GlobalStartTime.JD) / ((double)3600 / 86400);
            int hourNum = (int)Math.Ceiling((Convert.ToDouble(TempDOuble.ToString("0.00000"))));
            
            //遍历所有卫星
            foreach (var item in AllSatelliteMsg)
            {
                string satName = item.Name;//卫星名

                //计算仿真数据步长、拟合所需的数据组数
                ClockList = item.GenerateStepCLKErr(30);
                int SimStep = (int)((ClockList[1].SimTime.JD - ClockList[0].SimTime.JD) * 86400.0 + 0.0001);  //钟差数据仿真步长
                int Num = 0;  //计算只需2个小时轨道数据，Num为计算需要存储的组数        
                if (SimStep > 0)
                {
                    Num = 7200 / SimStep;
                }

                UTCTime FitTime =new UTCTime ();

                //拟合的小时数
                for(int i=0;i<hourNum;i++) 
                {
                    double[] ClkErrArr = new double[Num];
                    double[] TimArr = new double[Num];

                    List<ClkSimData> SatClockList = new List<ClkSimData>();
                    //获取从起算时刻开始的后2个小时数据
                    for (int j = 0; j < Num; j++)
			        {
                        SatClockList.Add(ClockList[i*(3600/SimStep)+j]);
                        ClkErrArr[j] = SatClockList[j].ClkError;
                        TimArr[j] = (SatClockList[j].SimTime.JD - SatClockList[0].SimTime.JD) * 86400.0;

                        FitTime = SatClockList[0].SimTime;
			        }

                    ClkErrFitMsg ClkFitMsg = new ClkErrFitMsg();
                    SatClkErrFitDLL.SatClkErrFit(FitTime, TimArr, ClkErrArr, Num, out ClkFitMsg);                   

                    //建立Uid与卫星钟差参数的联系
                    if (Parent.ClockErrDic.ContainsKey(satName))
                    {
                        Parent.ClockErrDic[satName].Add(ClkFitMsg);//为分星座存储钟差拟合数据提供单系统的数据
                    }
                    else
                    {
                        Parent.ClockErrDic.Add(satName, new List<ClkErrFitMsg>());//为分星座存储钟差拟合数据提供单系统的数据
                        Parent.ClockErrDic[satName].Add(ClkFitMsg);
                    }
                }
            }
        }

        #endregion

        #region 功能三：电离层参数拟合实现
        //一天计算一次电离层参数（8参）
        public void Msg_IonFit()
        {
            //电离层参数初始化
            int flag=IonFitDLL.IonFit_Init(BDSimObject.GlobalStartTime);

            //电离层拟合时间，如果跨天，要重新赋时间
            IonoFit_Input pIonoFit_Input = new IonoFit_Input();

            //获取仿真时所跨越长的天数
            double DayPass = (BDSimObject.GlobalEndTime.JD - BDSimObject.GlobalStartTime.JD);
                         
            //判断是否跨天,存数据
         //   if (DayPass > 1.0 || BDSimObject.GlobalEndTime.Day != BDSimObject.GlobalStartTime.Day)
          //  {
                UTCTime TempDay=new UTCTime (BDSimObject.GlobalStartTime.Year,BDSimObject.GlobalStartTime.Mon,BDSimObject.GlobalStartTime.Day,0,0,0,0);
                UTCTime EndDay = new UTCTime(BDSimObject.GlobalEndTime.Year, BDSimObject.GlobalEndTime.Mon, BDSimObject.GlobalEndTime.Day, 0, 0, 0, 0);
                TimeSpaceDll.CAL2UTC(out TempDay,1);
                TimeSpaceDll.CAL2UTC(out EndDay, 1);

                while (TempDay.JD <= EndDay.JD)
                {
                    TimeSpaceDll.CAL2UTC(out TempDay, 2);

                    IonoFit_OutputMsg IonoFitOutputMsg = new IonoFit_OutputMsg();

                    pIonoFit_Input.FitTime = TempDay;                
                    pIonoFit_Input.Select = 1;  //目前只用8参

                    IonoFit_Output pIonoFit_Output = new IonoFit_Output();
                    int flag2 = IonFitDLL.IonFit_Output(pIonoFit_Input, out pIonoFit_Output);

                    IonoFitOutputMsg.FitDay = pIonoFit_Input.FitTime;
                    IonoFitOutputMsg.IonoFitOutput = pIonoFit_Output;

                    Parent.IonoFitOutputMsgList.Add(IonoFitOutputMsg);

                    TempDay.JD++;
                }
                
        //    }
  

           

        }

        #endregion        



    }
}